package lcr;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class Test0044 {
}
class Solution0044_1 {
    public List<Integer> largestValues(TreeNode root) {
        Deque<TreeNode> deque = new LinkedList<>();
        ArrayList<Integer> list = new ArrayList<>();
        if (root==null) return list;

        deque.offer(root);
        while (!deque.isEmpty()){
            int size = deque.size();

            int max = Integer.MIN_VALUE;
            for (int i = 0; i < size; i++) {
                TreeNode poll = deque.poll();
                max = Math.max(max, poll.val);
                if (poll.left != null) deque.offer(poll.left);
                if (poll.right != null) deque.offer(poll.right);
            }
            list.add(max);
        }
        return list;
    }
}
